﻿Public Class frmStockEstadoCuenta

    Dim controller As New ControllerSigeco.controller_stock()

    Public Property lbProveedor() As String
        Get
            Return lblProveedor.Text
        End Get
        Set(ByVal value As String)
            lblProveedor.Text = value
        End Set
    End Property


    Private _codProveedor As Integer = 0
    Public Property codProveedor() As Integer
        Get
            Return _codProveedor
        End Get
        Set(ByVal value As Integer)
            _codProveedor = value
        End Set
    End Property

    Private Sub frmClienteEstadoCuenta_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        dgAnterior.AutoGenerateColumns = False
        dgDatos.AutoGenerateColumns = False
        dgTotal.AutoGenerateColumns = False

        dtpFechaInicio.Value = New DateTime(DateTime.Now.Year, 1, 1, 0, 0, 0)
        dtpFechaFin.Value = DateTime.Now
        GenerarDatos()

    End Sub

    Private Sub GenerarDatos()

        Try

            If codProveedor > 0 Then

                Dim dsDatos As New DataSet

                dsDatos = controller.get_Movimiento_Stock_EstadoCuenta(oiml.dbConn, codProveedor, dtpFechaInicio.Value, dtpFechaFin.Value)

                If dsDatos.Tables.Count = 3 Then

                    dgAnterior.DataSource = dsDatos.Tables(0)
                    dgDatos.DataSource = dsDatos.Tables(1)
                    dgTotal.DataSource = dsDatos.Tables(2)

                Else

                    dgDatos.DataSource = dsDatos.Tables(0)
                    dgTotal.DataSource = dsDatos.Tables(1)

                End If

            End If

        Catch ex As Exception

        End Try

    End Sub


    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub


    Private Sub btnGenerar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerar.Click
        GenerarDatos()
    End Sub

    Private m_frmBusMercaderia As frmMercaderiaBuscador
    Public Property frmBusMercaderia() As frmMercaderiaBuscador
        Get
            Return m_frmBusMercaderia
        End Get
        Set(ByVal value As frmMercaderiaBuscador)
            m_frmBusMercaderia = value
        End Set
    End Property

    Private Sub btnBuscMercaderia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscMercaderia.Click
        frmBusMercaderia = New frmMercaderiaBuscador
        frmBusMercaderia.ShowDialog()
        txtMercaderia.Text = frmBusMercaderia.MercaderiaDesc
        codProveedor = frmBusMercaderia.codMercaderia
        If codProveedor > 0 Then
            GenerarDatos()
        End If
    End Sub

End Class